<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\Admin\SystemSet;
use Illuminate\Http\Request;

class RuleController extends Controller
{
    public function index()
    {
        $result = [
            'leave'=>SystemSet::info('leave'),
            'make_up'=>SystemSet::info('make_up'),
            'optional_course'=>SystemSet::info('optional_course'),
            'integral_rul'=>SystemSet::info('integral_rul'),
            'user_service_rul'=>SystemSet::info('user_service_rul'),
            'cash_coupon_rul'=>SystemSet::info('cash_coupon_rul'),
            'goods_rul'=>SystemSet::info('goods_rul'),
            'expire_duration'=>SystemSet::goods_integral_expire(),
            'system_images'=>SystemSet::system_image(),
            'company_payment_code'=>SystemSet::system_image(2),
            'goods_integral_cove'=>SystemSet::system_image(3),
            'cash_picture'=>SystemSet::system_image(4),
        ];

        return view('admin.rule.index', $result);
    }

    public function edit(Request $request)
    {
        if(request()->ajax()){

            if($request->expire_duration <= 0)return self::fail('商品積分有效期不能小於0');

            SystemSet::edit($request);
            SystemSet::goods_integral($request);
        }

        return self::success();
    }

    public function rule_pints_cleared()
    {
        SystemSet::rule_pints_cleared();

        return self::success();
    }
}
